using BasicScript.Component;
using Game.Main.Model;
using Game.XH;
using SimpleJSON;
using UnityEngine;

namespace Game.Component
{
	public class TreasureItem : BaseItem
	{
		public enum State
		{
			Close = 0,
			Open = 1
		}

		private Transform door;

		private State state;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			door = frontMask.Find("Door");
			door.SetLocalZ(-2E-05f);
			SetState((State)data.state);
			if (state == State.Open)
			{
				door.GetComponent<FrameAnimation>().GotoLastFrame();
			}
		}

		private void SetState(State val)
		{
			if (state != val)
			{
				state = val;
				if (state == State.Open)
				{
					SetColliderEnabled(false);
                    SetPlatformColliderEnable(true);
				}
			}
		}

		public void OpenStatue()
		{
			if (state != State.Open)
			{
				SetState(State.Open);
				FrameAnimation component = door.GetComponent<FrameAnimation>();
				component.Play();
			}
		}

		public override void PackData(JSONObject obj)
		{
			base.PackData(obj);
			obj["33"] = (int)state;
		}
	}
}
